// 应用基础类型定义

export type Theme = 'light' | 'dark' | 'auto'

// ============================================
// 设备相关类型
// ============================================

export interface Device {
  id: string
  name: string
  device_type: 'real_phone' | 'cloud_phone' | 'emulator'
  platform: 'android' | 'ios'
  status: 'online' | 'offline' | 'busy' | 'error' | 'maintenance'
  
  connection_config?: any
  device_info?: any
  performance_config?: any
  proxy_config?: any
  
  last_heartbeat?: string
  last_error?: string
  uptime_seconds?: number
  
  total_tasks_completed: number
  total_errors: number
  
  created_at: string
  updated_at: string
}

export interface CreateDeviceRequest {
  name: string
  device_type: 'real_phone' | 'cloud_phone' | 'emulator'
  platform: 'android' | 'ios'
  connection_config: any
}

export interface DeviceGroup {
  id: string
  name: string
  description?: string
  group_type: 'custom' | 'location' | 'platform'
  device_count: number
  created_at: string
}

// ============================================
// 社媒账号相关类型
// ============================================

export interface SocialAccount {
  id: string
  platform: 'tiktok' | 'facebook' | 'instagram' | 'youtube' | 'twitter'
  username: string
  display_name?: string
  email?: string
  
  credential_type: 'password' | 'token' | 'cookie'
  account_info?: any
  security_settings?: any
  operation_settings?: any
  
  assigned_device_id?: string
  status: 'active' | 'inactive' | 'suspended' | 'banned' | 'under_review'
  
  last_login?: string
  last_activity?: string
  login_failures: number
  
  created_at: string
  updated_at: string
}

export interface CreateAccountRequest {
  platform: 'tiktok' | 'facebook' | 'instagram' | 'youtube' | 'twitter'
  username: string
  display_name?: string
  email?: string
  credentials: any
}

// ============================================
// 任务相关类型
// ============================================

export interface Task {
  id: string
  name: string
  
  task_type: 'post_content' | 'like_posts' | 'follow_users' | 'comment' | 'scrape_data'
  category: 'content' | 'engagement' | 'growth' | 'maintenance'
  
  strategy_id?: string
  account_id: string
  device_id?: string
  parent_task_id?: string
  
  status: 'pending' | 'queued' | 'running' | 'completed' | 'failed' | 'cancelled' | 'retrying'
  priority: number
  
  scheduled_at?: string
  deadline?: string
  
  config: any
  input_data?: any
  output_data?: any
  
  started_at?: string
  completed_at?: string
  execution_duration?: number
  
  retry_count: number
  max_retries: number
  retry_delay: number
  
  error_message?: string
  error_code?: string
  error_details?: any
  
  progress_percentage: number
  current_step?: string
  total_steps: number
  
  created_at: string
  updated_at: string
}

export interface CreateTaskRequest {
  name: string
  task_type: 'post_content' | 'like_posts' | 'follow_users' | 'comment' | 'scrape_data'
  account_id: string
  strategy_id?: string
  config: any
  priority?: number
  scheduled_at?: string
}

export interface TaskLog {
  id: number
  task_id: string
  log_level: 'debug' | 'info' | 'warning' | 'error' | 'critical'
  message: string
  details?: any
  step_name?: string
  step_index?: number
  screenshot_path?: string
  attachments?: string[]
  timestamp: string
}

export interface AutomationStrategy {
  id: string
  name: string
  description?: string
  platform: string
  strategy_type: 'posting' | 'engagement' | 'growth' | 'monitoring' | 'data_collection'
  
  config_template: any
  execution_settings?: any
  success_metrics?: any
  
  is_active: boolean
  usage_count: number
  success_rate: number
  
  version: number
  parent_strategy_id?: string
  
  created_at: string
  updated_at: string
}

// ============================================
// 内容相关类型
// ============================================

export interface ContentItem {
  id: string
  title: string
  
  content_type: 'text' | 'image' | 'video' | 'template' | 'hashtag_set'
  platform: string
  category: string
  
  content: string
  thumbnail_path?: string
  metadata?: any
  
  usage_count: number
  last_used?: string
  
  quality_score: number
  performance_metrics?: any
  
  is_active: boolean
  is_featured: boolean
  
  version: number
  original_content_id?: string
  
  created_at: string
  updated_at: string
}

export interface CreateContentRequest {
  title: string
  content_type: 'text' | 'image' | 'video' | 'template' | 'hashtag_set'
  platform: string
  category?: string
  content: string
  metadata?: any
}

// ============================================
// 统计分析相关类型
// ============================================

export interface AnalyticsData {
  id: string
  account_id: string
  platform: string
  data_source: 'api' | 'scraping' | 'manual'
  
  metric_type: 'followers' | 'likes' | 'views' | 'comments' | 'shares' | 'engagement_rate'
  metric_value: number
  metric_unit: 'count' | 'percentage' | 'rate' | 'duration'
  
  date_recorded: string
  time_period: 'hourly' | 'daily' | 'weekly' | 'monthly'
  
  additional_data?: any
  confidence_score: number
  is_estimated: boolean
  
  created_at: string
}

export interface AnalyticsQuery {
  account_id?: string
  platform?: string
  metric_type?: string
  date_range?: [string, string]
  time_period?: 'daily' | 'weekly' | 'monthly'
}

// ============================================
// 代理相关类型
// ============================================

export interface Proxy {
  id: string
  proxy_type: 'http' | 'https' | 'socks5'
  host: string
  port: number
  username?: string
  
  country_code?: string
  city?: string
  isp?: string
  
  status: 'active' | 'inactive' | 'banned' | 'testing'
  response_time_ms: number
  
  last_used?: string
  success_count: number
  failure_count: number
  total_bandwidth_kb: number
  
  last_health_check?: string
  health_status: 'healthy' | 'slow' | 'unstable' | 'down'
  
  cost_per_gb: number
  monthly_limit_gb: number
  
  created_at: string
  updated_at: string
}

// ============================================
// 系统配置相关类型
// ============================================

export interface SystemConfig {
  id: number
  config_key: string
  config_value: string
  description?: string
  config_type: 'string' | 'number' | 'boolean' | 'json'
  is_encrypted: boolean
  created_at: string
  updated_at: string
}

export interface UserPreference {
  id: number
  preference_key: string
  preference_value: string
  value_type: 'string' | 'number' | 'boolean' | 'json'
  category: 'general' | 'ui' | 'automation' | 'security'
  description?: string
  created_at: string
  updated_at: string
}

// ============================================
// API 响应相关类型
// ============================================

export interface ApiResponse<T = any> {
  success: boolean
  data?: T
  message?: string
  error?: string
}

export interface PaginatedResponse<T> {
  items: T[]
  total: number
  page: number
  limit: number
  has_more: boolean
}

// ============================================
// 组件相关类型
// ============================================

export interface TableColumn {
  key: string
  label: string
  width?: number | string
  sortable?: boolean
  filterable?: boolean
  formatter?: (value: any, row: any) => string
}

export interface FormField {
  key: string
  label: string
  type: 'input' | 'select' | 'textarea' | 'switch' | 'date' | 'number'
  required?: boolean
  placeholder?: string
  options?: { label: string; value: any }[]
  rules?: any[]
}

export interface ChartData {
  labels: string[]
  datasets: {
    label: string
    data: number[]
    backgroundColor?: string | string[]
    borderColor?: string
    borderWidth?: number
  }[]
}

// ============================================
// 事件相关类型
// ============================================

export interface DeviceStatusEvent {
  device_id: string
  status: string
  timestamp: string
}

export interface TaskProgressEvent {
  task_id: string
  progress: number
  current_step: string
  timestamp: string
}

export interface SystemNotification {
  id: string
  type: 'info' | 'success' | 'warning' | 'error'
  title: string
  message: string
  timestamp: string
  read: boolean
}